package com.itheima.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.CategoryMapper;
import com.itheima.mapper.DishMapper;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Category;
import com.itheima.pojo.Dish;
import com.itheima.pojo.Setmeal;
import com.itheima.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Resource
    private SetmealMapper setmealMapper;

    @Resource
    private DishMapper dishMapper;

    @Resource
    private CategoryMapper categoryMapper;
    @Override
    public boolean deleteById(Long id) {

        LambdaQueryWrapper<Dish> qw = new LambdaQueryWrapper<>();
        qw.eq( Dish::getCategoryId,id);
        Integer count = dishMapper.selectCount(qw);
        if (count> 0) {
            return false;
        }

        LambdaQueryWrapper<Setmeal> lqw = new LambdaQueryWrapper<>();
        lqw.eq( Setmeal::getCategoryId,id);

        Integer count2 = setmealMapper.selectCount(lqw);
        if (count2 > 0) {
            return false;
        }

        int i = categoryMapper.deleteById(id);
        return true;

    }
}
